package com.whfc.wxmp.api.fvs.service.impl;

import com.whfc.common.exception.BizException;
import com.whfc.common.result.PageData;
import com.whfc.common.result.ResultEnum;
import com.whfc.fvs.dto.FvsDeviceDTO;
import com.whfc.fvs.dto.FvsStreamDTO;
import com.whfc.fvs.dto.FvsTokenDTO;
import com.whfc.fvs.enums.FvsDevicePtzOption;
import com.whfc.fvs.param.FvsDeviceListParam;
import com.whfc.fvs.service.FvsDeviceService;
import com.whfc.wxmp.api.fvs.service.WxFvsDeviceService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Method;
import org.springframework.stereotype.Service;

/**
 * @author qzexing
 * @version 1.0
 * @date 2021/12/15 16:44
 */
@Service
public class WxFvsDeviceServiceImpl implements WxFvsDeviceService {

    @DubboReference(interfaceClass = FvsDeviceService.class, version = "1.0.0",
            methods = {@Method(name = "ptz", async = true, isReturn = false)})
    private FvsDeviceService fvsDeviceService;

    @Override
    public PageData<FvsDeviceDTO> list(FvsDeviceListParam fvsDeviceListParam) {
        return fvsDeviceService.list(fvsDeviceListParam);
    }

    @Override
    public FvsStreamDTO getStreamUrl(Integer deviceId) {
        return fvsDeviceService.getStreamUrl(deviceId);
    }

    @Override
    public FvsTokenDTO getToken(Integer deptId, Integer platform) {
        return fvsDeviceService.getToken(deptId, platform);
    }

    @Override
    public void ptz(Integer deviceId, Integer ptzOption) {
        FvsDevicePtzOption devicePtzOption = FvsDevicePtzOption.parseValue(ptzOption);
        if (devicePtzOption == null) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "操作类型错误.");
        }
        fvsDeviceService.ptz(deviceId, devicePtzOption);
    }
}
